package top.dancun.eascourse.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import top.dancun.common.utils.DataUtils;
import top.dancun.eascourse.entity.ExaminationArrangementEntity;
import top.dancun.eascourse.entity.ScoresEntity;
import top.dancun.eascourse.service.ExaminationArrangementService;
import top.dancun.common.utils.PageUtils;
import top.dancun.common.utils.R;



/**
 * 考试安排
 *
 * @author dancun
 * @email message@dancun.top
 * @date 2022-11-05 10:12:23
 */
@RestController
@RequestMapping("/examinationarrangement")
public class ExaminationArrangementController extends AbstractController{
    @Autowired
    private ExaminationArrangementService examinationArrangementService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("eascourse:examinationarrangement:list")
    public R list(@RequestBody Map<String, Object> params){
        Map<String ,String > data = DataUtils.mapAddNoEmpty(params, ScoresEntity.class);
        PageUtils page = examinationArrangementService.queryPage(params,data);

        return R.ok().put("page", page);
    }

    /**
     * 我的考试
     */
    @RequestMapping("/getmyexam")
    public R getMyExam(@RequestBody Map<String, Object> params){
        String  userId = getUserId();
        params.put("studentId",userId);
        Map<String ,String > data = DataUtils.mapAddNoEmpty(params, ScoresEntity.class);
        PageUtils page = examinationArrangementService.queryPage(params,data);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("eascourse:examinationarrangement:info")
    public R info(@PathVariable("id") Long id){
		ExaminationArrangementEntity examinationArrangement = examinationArrangementService.getById(id);

        return R.ok().put("examinationArrangement", examinationArrangement);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("eascourse:examinationarrangement:save")
    public R save(@RequestBody ExaminationArrangementEntity examinationArrangement){
		examinationArrangementService.save(examinationArrangement);

        return R.ok();
    }
    /**
     * 考试安排
     */
    @PostMapping("arrangment")
    @RequiresPermissions("eascourse:examinationarrangement:save")
    public R arrangment(@RequestBody Map<String,String> params) throws Exception {
        examinationArrangementService.arrangment(params);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("eascourse:examinationarrangement:update")
    public R update(@RequestBody ExaminationArrangementEntity examinationArrangement){
		examinationArrangementService.updateById(examinationArrangement);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("eascourse:examinationarrangement:delete")
    public R delete(@RequestBody Long[] ids){
		examinationArrangementService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
